/**
 *
 * Copyright  2011 Nokia Corporation.
 * tuomo.hirvonen@digia.com
 *
 */


#ifndef __PARTICLESYSTEM__
#define __PARTICLESYSTEM__


class TheGame;

#define MAX_PARTICLES 256

/**
 * Structure defining a type and behaviour of a particle
 */
struct ParticleSprayType {
    int renderType;
    int firstBlock;
    int blockCount;


    float gravity;
    float fraction;

    float lifeTime;
    float lifeTimeRandom;

    float size;
    float sizeRandom;

    float sizeInc;
    float sizeIncRandom;

    float angle;
    float angleRandom;

    float angleInc;
    float angleIncRandom;

    float col[4];
};


/**
 * Structure defining a single particle instance. Refers to type.
 */
struct Particle {
    float x,y, size, angle;
    float dx, dy, sizeinc, angleinc;
    float lifeTime;

    unsigned int tileIndex;
    ParticleSprayType *spray;
};


/**
 * A system that runs the particles and renders them
 */
class ParticleSystem {
public:
    ParticleSystem( TheGame *game );
    virtual ~ParticleSystem();

    static void initSprayType( ParticleSprayType *target,
                        int firstBlock,
                        int blockCount,
                        float gravity,
                        float fraction,
                        float lifeTime,
                        float lifeTimeRandom,
                        float size,
                        float sizeRandom,
                        float sizeinc,
                        float sizeincRandom,
                        float angle = 0,
                        float angleRandom = 0,
                        float angleinc= 0,
                        float angleincRandom=0,
                        int type = 0);

    void spray( int count,
                float x, float y, float posrandom,
                float dx, float dy, float dirrandom,
                ParticleSprayType *spray );

    void run( float frameDelta );
    void render(float posx, float posy, ParticleSprayType *typeToRender = 0, bool flicker = false);


protected:
    TheGame *game;
    int m_cp;
    Particle m_particles[ MAX_PARTICLES ];
};

#endif
